package com.yzlshdg.warehouse.controller;

import com.yzlshdg.warehouse.entity.Supply;
import com.yzlshdg.warehouse.service.SupplyService;
import com.yzlshdg.warehouse.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author asus
 * @version 1.0
 * @description: TODO
 * @date 2025/5/10 16:17
 */
@RestController
@RequestMapping("/supply")
public class SupplyController {

    @Autowired
    private SupplyService supplyService;

    @GetMapping("/list")
    public Result getAllSupply() {
        List<Supply> list = supplyService.getAllSupply();
        return Result.ok(list);
    }

    @GetMapping("/{id}")
    public Result getSupplyById(@PathVariable("id") String supplyId) {
        Supply supply = supplyService.getSupplyById(supplyId);
        return Result.ok(supply);
    }

    @PostMapping("/add")
    public Result addSupply(@RequestBody Supply supply) {
        int rows = supplyService.addSupply(supply);
        return rows > 0 ? Result.ok() : Result.fail();
    }

    @PutMapping("/update")
    public Result updateSupply(@RequestBody Supply supply) {
        int rows = supplyService.updateSupply(supply);
        return rows > 0 ? Result.ok() : Result.fail();
    }

    @DeleteMapping("delete/{id}")
    public Result deleteSupply(@PathVariable("id") String supplyId) {
        int rows = supplyService.deleteSupply(supplyId);
        return rows > 0 ? Result.ok() : Result.fail();
    }
}
